<?php
/**
 * 币ticker信息redis数据库
 * @App	
 * @Group 
 * @Action CoinTickerRedis
 * @author lilei
 * @date 2018年5月24日
 * // // redis 39.104.163.200:6379  db1  key feixiaohao_token 和 ticker 两个  field 都是符号名字比如BTC就是比特币
 * {
    "max_supply": 21000000,
    "id": 1,
    "circulating_supply": 17059725,
    "symbol": "BTC",
    "name": "Bitcoin",
    "last_updated": 1527501272,
    "rank": 1,
    "quotes": {
        "USD": {
            "price": 7242.05,
            "percent_change_7d": -14.74,
            "market_cap": 123547381436,
            "percent_change_24h": -1.33,
            "volume_24h": 4724060000,
            "percent_change_1h": 0.05
        }
    },
    "total_supply": 17059725,
    "website_slug": "bitcoin"
}
 */
namespace app\common\redis;

class CoinTickerRedis extends RedisModel {
	/**
	 * 
	 * @var
	 */
	public $max_supply; //double
	public $id; //int
	public $circulating_supply; //double
	public $symbol; //String
	public $name; //String
	public $last_updated; //int
	public $rank; //int
	public $quotes; //Quotes
	public $total_supply; //double
	public $website_slug; //String
	
	
	
	/**
	 * Redis配置名称
	 * @var string
	 */
	public $redis = 'coinExchangeData';
	
	/**
	 * Redis key
	 * @var string
	 */
	public $key = 'ticker';
	
	/**
	 * 获取所有Ticker信息列表
	 * @return array
	 */
	public function GetAllTickersInfoList() {
		$res = $this->HashGetAll();
		if ( !$res ) {
			return array();
		}
		foreach ( $res as &$v) {
			$v = json_decode($v, true);
			if ( $v ) {
				$v = $this->fillTickerItem($v);
			}
		}
		return $res;
	}
	
	/**
	 * 通过Token的编号(Symbol)获取ticker信息
	 * @param string $Symbol
	 * @return array
	 */
	public function GetTickerInfo( $Symbol ) {
		$res = $this->HashGetByField($Symbol);
		if ( !$res ) {
			return array();
		}
		$res = json_decode($res, true);
		if ( $res ) {
			$res = $this->fillTickerItem($res);
		}else {
			$res = array();
		}
		return $res;
	}
	
	/**
	 * 完善TickerItem数据
	 * @param array $item
	 * @return array
	 */
	public function fillTickerItem( $item ) {
		$item['slug'] = $item['website_slug'];
		return $item;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}